```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netty 高性能网络通信框架解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background: #1e1e1e;
            padding: 8px 12px;
            border-radius: 8px 8px 0 0;
            font-size: 0.85rem;
            display: flex;
            justify-content: space-between;
        }
        .code-language {
            color: #ccc;
        }
        .copy-btn {
            color: #9e9e9e;
            cursor: pointer;
            transition: all 0.2s;
        }
        .copy-btn:hover {
            color: #fff;
        }
        .highlight-card {
            transition: all 0.3s ease;
            border-left: 4px solid transparent;
        }
        .highlight-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            border-left-color: #4f46e5;
        }
        .section-divider {
            position: relative;
            height: 80px;
            overflow: hidden;
        }
        .section-divider svg {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        .mermaid-tooltip {
            position: absolute;
            background: white;
            padding: 8px 12px;
            border-radius: 4px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            z-index: 100;
            font-size: 14px;
            max-width: 300px;
            display: none;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-6">
        <div class="max-w-5xl mx-auto text-center">
            <div class="inline-block px-3 py-1 mb-4 text-sm font-medium rounded-full bg-white bg-opacity-20">
                <i class="fas fa-bolt mr-2"></i>高性能网络框架
            </div>
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">Netty 高性能网络通信框架</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                探索Netty如何通过创新的架构设计和优化策略，实现低延迟、高吞吐量的网络通信解决方案
            </p>
            <div class="mt-10 flex justify-center space-x-4">
                <a href="#content" class="px-6 py-3 bg-white text-indigo-700 font-medium rounded-lg hover:bg-opacity-90 transition-all">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#visualization" class="px-6 py-3 bg-white bg-opacity-20 text-white font-medium rounded-lg hover:bg-opacity-30 transition-all">
                    <i class="fas fa-project-diagram mr-2"></i>架构图解
                </a>
            </div>
        </div>
    </section>

    <!-- Content Section -->
    <section id="content" class="py-16 px-6 max-w-5xl mx-auto">
        <!-- Introduction -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">Netty 的高性能设计哲学</h2>
            <div class="prose max-w-none text-gray-700">
                <p class="text-lg leading-relaxed">
                    Netty 作为一款高性能的网络通信框架，其设计哲学围绕着低延迟、高吞吐量两大核心目标展开。通过创新的架构设计和精细的优化策略，Netty 在现代分布式系统中扮演着至关重要的角色。
                </p>
            </div>
        </div>

        <!-- Design Goals -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">1. Netty 的高性能设计目标</h2>
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="highlight-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-indigo-600 mb-3">
                        <i class="fas fa-tachometer-alt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">低延迟高吞吐</h3>
                    <p class="text-gray-600">通过优化内存管理和I/O操作，显著减少系统开销，实现极致的性能表现。</p>
                </div>
                <div class="highlight-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-indigo-600 mb-3">
                        <i class="fas fa-expand-arrows-alt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">高度可扩展性</h3>
                    <p class="text-gray-600">灵活的架构设计使Netty能适应从嵌入式系统到大规模分布式服务的各种场景。</p>
                </div>
                <div class="highlight-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="text-indigo-600 mb-3">
                        <i class="fas fa-exchange-alt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">非阻塞I/O模型</h3>
                    <p class="text-gray-600">基于事件驱动的异步模型，最大化并发性能，避免传统阻塞式I/O的效率瓶颈。</p>
                </div>
            </div>
        </div>

        <!-- Section Divider -->
        <div class="section-divider my-12">
            <svg viewBox="0 0 1200 120" preserveAspectRatio="none">
                <path d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z" opacity=".25" fill="#4f46e5"></path>
                <path d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z" opacity=".5" fill="#4f46e5"></path>
                <path d="M0,0V5.63C149.93,59,314.09,71.32,475.83,42.57c43-7.64,84.23-20.12,127.61-26.46,59-8.63,112.48,12.24,165.56,35.4C827.93,77.22,886,95.24,951.2,90c86.53-7,172.46-45.71,248.8-84.81V0Z" fill="#4f46e5"></path>
            </svg>
        </div>

        <!-- Non-blocking I/O -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">2. 非阻塞 I/O 模型优化</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        Netty 的非阻塞 I/O 模型基于 Java NIO 库，采用优化的事件驱动机制。核心组件 <code class="bg-gray-100 px-2 py-1 rounded">EventLoop</code> 和 <code class="bg-gray-100 px-2 py-1 rounded">Channel</code> 协同工作，彻底避免了传统 I/O 模型中的阻塞操作。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-sync-alt"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">事件轮询机制</h4>
                                <p class="text-gray-600">使用 <code class="bg-gray-100 px-1 py-0.5 rounded">Selector</code> 监听多通道就绪状态，通过 <code class="bg-gray-100 px-1 py-0.5 rounded">select()</code> 轮询避免线程阻塞。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-database"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">非阻塞读取</h4>
                                <p class="text-gray-600">仅在 <code class="bg-gray-100 px-1 py-0.5 rounded">Channel</code> 就绪时执行 I/O 操作，消除无意义的等待时间。</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class NioEventLoop extends SingleThreadEventLoop {
    @Override
    public void run() {
        // NIO 事件循环
        for (;;) {
            // 轮询就绪事件并处理
            SelectionKey key = selector.select();
            if (key.isAcceptable()) {
                // 处理接入请求
            }
            // 其他事件处理
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Memory Management -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">3. 内存管理优化</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="order-2 md:order-1">
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class PooledByteBufAllocator extends ByteBufAllocator {
    @Override
    public ByteBuf directBuffer(int capacity, int maxCapacity) {
        // 使用直接内存，避免堆内存的拷贝
        return new PooledDirectByteBuf(this, capacity, maxCapacity);
    }
}</code></pre>
                    </div>
                </div>
                <div class="order-1 md:order-2">
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        内存管理是 Netty 性能优化的核心战场。通过多项创新技术，Netty 大幅减少了内存拷贝、避免了内存泄漏，显著提升了 I/O 性能。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-memory"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">直接内存分配</h4>
                                <p class="text-gray-600">通过 <code class="bg-gray-100 px-1 py-0.5 rounded">Unsafe</code> 直接访问系统内存，完全绕过 JVM 堆内存，消除拷贝开销。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-recycle"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">内存池化技术</h4>
                                <p class="text-gray-600">引入先进的内存池机制，通过复用内存块显著降低分配/回收的系统开销。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Zero-Copy -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">4. 零拷贝优化技术</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        零拷贝是 Netty 性能优化的杀手锏。通过 <code class="bg-gray-100 px-2 py-1 rounded">DirectByteBuf</code> 和 <code class="bg-gray-100 px-2 py-1 rounded">Unsafe</code> 类的巧妙运用，Netty 实现了数据在传输过程中的零拷贝，性能提升立竿见影。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-file-export"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">文件传输优化</h4>
                                <p class="text-gray-600">使用 <code class="bg-gray-100 px-1 py-0.5 rounded">transferTo()</code> 方法直接桥接文件与网络通道，省去中间内存拷贝。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-network-wired"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">网络传输优化</h4>
                                <p class="text-gray-600">借助 <code class="bg-gray-100 px-1 py-0.5 rounded">DirectByteBuf</code> 直接操作系统内存，减少数据处理环节。</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class DefaultFileRegion implements FileRegion {
    @Override
    public long transferTo(WritableByteChannel target) throws IOException {
        // 直接将数据传输到目标通道，避免中间的内存拷贝
        return fileChannel.transferTo(position(), count(), target);
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section Divider -->
        <div class="section-divider my-12">
            <svg viewBox="0 0 1200 120" preserveAspectRatio="none">
                <path d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z" opacity=".25" fill="#4f46e5"></path>
                <path d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z" opacity=".5" fill="#4f46e5"></path>
                <path d="M0,0V5.63C149.93,59,314.09,71.32,475.83,42.57c43-7.64,84.23-20.12,127.61-26.46,59-8.63,112.48,12.24,165.56,35.4C827.93,77.22,886,95.24,951.2,90c86.53-7,172.46-45.71,248.8-84.81V0Z" fill="#4f46e5"></path>
            </svg>
        </div>

        <!-- Event-Driven Model -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">5. 事件驱动与线程模型</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="order-2 md:order-1">
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class DefaultEventLoopGroup implements EventLoopGroup {
    @Override
    public EventLoop next() {
        // 获取下一个事件循环
        return eventLoops[nextEventLoopIndex++];
    }

    @Override
    public void execute(Runnable task) {
        // 将任务提交到事件循环处理
        next().execute(task);
    }
}</code></pre>
                    </div>
                </div>
                <div class="order-1 md:order-2">
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        Netty 采用创新的事件驱动和线程池模型，将 I/O 操作与事件处理逻辑解耦，通过精细的任务调度策略实现卓越的性能表现。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-redo"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">事件循环机制</h4>
                                <p class="text-gray-600"><code class="bg-gray-100 px-1 py-0.5 rounded">EventLoopGroup</code> 智能分配连接事件到不同 <code class="bg-gray-100 px-1 py-0.5 rounded">EventLoop</code>，实现高效处理。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-tasks"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">任务调度优化</h4>
                                <p class="text-gray-600">任务被提交到空闲工作线程，多线程并行处理显著提升并发吞吐量。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- ChannelPipeline -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">6. ChannelPipeline 设计</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        <code class="bg-gray-100 px-2 py-1 rounded">ChannelPipeline</code> 是 Netty 高性能架构的核心组件之一。其链式处理机制和异步特性为网络事件处理提供了极高的灵活性和效率。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-link"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">链式处理流程</h4>
                                <p class="text-gray-600"><code class="bg-gray-100 px-1 py-0.5 rounded">ChannelHandler</code> 链式处理事件数据，避免多次拷贝，提高处理效率。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-random"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">并行处理能力</h4>
                                <p class="text-gray-600">异步处理机制允许不同任务在多个线程间并行执行，大幅提升处理速度。</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class DefaultChannelPipeline implements ChannelPipeline {
    private final List&lt;ChannelHandler&gt; handlers = new ArrayList&lt;&gt;();

    @Override
    public void fireChannelRead(Object msg) {
        for (ChannelHandler handler : handlers) {
            handler.channelRead(msg);
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Async I/O -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">7. 异步 I/O 与回调机制</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="order-2 md:order-1">
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class ChannelFutureImpl implements ChannelFuture {
    private final Promise&lt;Void&gt; promise = new DefaultPromise&lt;&gt;(eventLoop);

    public ChannelFuture addListener(GenericFutureListener&lt;? extends Future&lt;? super Void&gt;&gt; listener) {
        promise.addListener(listener);  // 增加回调监听器
        return this;
    }
}</code></pre>
                    </div>
                </div>
                <div class="order-1 md:order-2">
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        Netty 全面拥抱异步 I/O 和回调机制，通过 <code class="bg-gray-100 px-2 py-1 rounded">ChannelFuture</code> 和 <code class="bg-gray-100 px-2 py-1 rounded">Promise</code> 的完美配合，实现了高效的非阻塞操作和灵活的结果处理。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-bolt"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">异步执行模式</h4>
                                <p class="text-gray-600">I/O 操作通过 <code class="bg-gray-100 px-1 py-0.5 rounded">ChannelFuture</code> 异步执行，调用线程无需阻塞等待结果。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-bell"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">回调通知机制</h4>
                                <p class="text-gray-600">操作完成后自动触发预设回调，保证非阻塞执行的同时准确通知调用方。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Load Balancing -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif border-l-4 border-indigo-500 pl-4">8. 负载均衡与资源调度</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-gray-700 leading-relaxed">
                        面对海量并发请求，Netty 通过智能的负载均衡和动态资源调度策略，确保系统资源得到最优化利用，维持高性能服务能力。
                    </p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-balance-scale"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">动态负载均衡</h4>
                                <p class="text-gray-600"><code class="bg-gray-100 px-1 py-0.5 rounded">EventLoopGroup</code> 根据实时负载智能调度任务，防止线程过载。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1 mr-3 text-indigo-500">
                                <i class="fas fa-adjust"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-gray-800">自适应资源分配</h4>
                                <p class="text-gray-600">持续监控各 <code class="bg-gray-100 px-1 py-0.5 rounded">EventLoop</code> 负载情况，动态调整策略确保最佳性能。</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <pre><code class="language-java p-4 block overflow-x-auto">public class MultithreadEventLoopGroup extends DefaultEventLoopGroup {
    @Override
    public EventLoop next() {
        // 根据负载情况动态选择事件循环
        if (load > THRESHOLD) {
            return nextEventLoopInRoundRobin();  // 轮询调度
        } else {
            return nextEventLoopInLeastBusy();   // 最少忙碌调度
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section id="visualization" class="py-20 px-6 bg-gray-50">
        <div class="max-w-5xl mx-auto">
            <h2 class="text-3xl font-bold mb-12 text-center text-gray-800 font-serif">Netty 架构可视化</h2>
            
            <div class="bg-white rounded-xl shadow-md p-6 mb-12">
                <h3 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-2">Netty 核心组件交互图</h3>
                <div class="mermaid">
                    graph TD
                    A[客户端请求] --> B(Channel)
                    B --> C[EventLoop]
                    C --> D[ChannelPipeline]
                    D --> E[ChannelHandler1]
                    D --> F[ChannelHandler2]
                    D --> G[ChannelHandlerN]
                    E --> H[业务逻辑处理]
                    F --> H
                    G --> H
                    H --> I[返回响应]
                    I --> B
                    C --> J[ByteBuf 内存管理]
                    C --> K[零拷贝优化]
                    C --> L[异步回调机制]
                    style A fill:#f0f9ff,stroke:#0369a1
                    style B fill:#e0f2fe,stroke:#0ea5e9
                    style C fill:#dbeafe,stroke:#3b82f6
                    style D fill:#e0e7ff,stroke:#6366f1
                    style E,F,G fill:#ede9fe,stroke:#8b5cf6
                    style H fill:#ecfdf5,stroke:#10b981
                    style I fill:#f0fdf4,stroke:#22c55e
                    style J,K,L fill:#f5f3ff,stroke:#7c3aed
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6">
                    <h3 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-2">内存管理流程</h3>
                    <div class="mermaid">
                        flowchart LR
                        A[内存请求] --> B{池中有可用内存?}
                        B -->|是| C[从内存池分配]
                        B -->|否| D[新建内存块]
                        C --> E[业务使用]
                        D --> E
                        E --> F{释放内存?}
                        F -->|是| G[返回内存池]
                        F -->|否| H[继续持有]
                        style A fill:#f5f3ff,stroke:#7c3aed
                        style B fill:#ede9fe,stroke:#8b5cf6
                        style C,D fill:#e0e7ff,stroke:#6366f1
                        style E fill:#dbeafe,stroke:#3b82f6
                        style F fill:#ede9fe,stroke:#8b5cf6
                        style G,H fill:#e0e7ff,stroke:#6366f1
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6">
                    <h3 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-2">事件处理流程</h3>
                    <div class="mermaid">
                        sequenceDiagram
                        participant C as Client
                        participant B as Bootstrap
                        participant EL as EventLoop
                        participant CP as ChannelPipeline
                        participant H as Handler
                        C->>B: 发起连接
                        B->>EL: 注册Channel
                        EL->>CP: 触发连接事件
                        CP->>H: 处理连接
                        H->>CP: 返回响应
                        CP->>EL: 写回数据
                        EL->>C: 返回响应
                        Note right of EL: 非阻塞异步处理
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10 px-6">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术奥秘，分享知识精华</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>访问技术小馆
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            sequence: {
                diagramMarginX: 50,
                diagramMarginY: 10,
                boxTextMargin: 5,
                noteMargin: 10,
                messageMargin: 35,
                mirrorActors: true
            }
        });

        // Copy code functionality
        document.querySelectorAll('.copy-btn').forEach(btn => {
            btn.addEventListener('click', function() {
                const codeBlock = this.closest('.code-block').querySelector('code');
                const range = document.createRange();
                range.selectNode(codeBlock);
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(range);
                document.execCommand('copy');
                window.getSelection().removeAllRanges();
                
                const originalText = this.innerHTML;
                this.innerHTML = '<i class="fas fa-check mr-1"></i> 已复制';
                setTimeout(() => {
                    this.innerHTML = originalText;
                }, 2000);
            });
        });

        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```